package com.example.idlefish.GoodsInfo.ActivityContract

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.MediaStore
import androidx.activity.result.contract.ActivityResultContract

class TakePhotoActivityContract:ActivityResultContract<Uri, Boolean>(){
    override fun createIntent(context: Context, input: Uri): Intent {

        val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
        intent.putExtra(MediaStore.EXTRA_OUTPUT, input)
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1)
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
        //授予应用读写Uri的权限
        return intent
    }

    override fun parseResult(resultCode: Int, intent: Intent?): Boolean {
        return when(resultCode){
            Activity.RESULT_OK->true
            Activity.RESULT_CANCELED->false
            else->false
        }
    }
}
